package package_1;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class exercise_3 {
	public static void main(String[] args) throws IOException {
		String pathin = "C:\\Users\\ybrho\\Pictures\\Camera Roll\\yalta_conference.jpg";
		File file = new File(pathin);
		DataInputStream dis = null ;
		DataOutputStream dos = null;
		if (file.exists()) {
			dis = new DataInputStream(new FileInputStream(pathin));
			dos = new DataOutputStream(
					new FileOutputStream(file.getParent() + "\\yalta_conference_copy.jpg"));

		}
		
		byte[] bytes = new byte[1024];
		int len = -1;
		while((len = dis.read(bytes)) != -1) {
			//一边读一边写
			dos.write(bytes, 0, len);
			dos.flush();
		}
		
		if(dos != null) {
			try {
				dos.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(dis != null) {
			try {
				dis.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	}
}}
